// This file contains social-related API functions
import type { 
  UnlikeCourseData, UnlikeCourseResponses,
  UnfollowUserData, UnfollowUserResponses,
  LikeCourseData, LikeCourseResponses,
  FollowUserData, FollowUserResponses,
  SyncRedisToDatabaseData, SyncRedisToDatabaseResponses,
  GetUserFollowingListData, GetUserFollowingListResponses,
  GetUserFollowersListData, GetUserFollowersListResponses,
  GetUserStatsData, GetUserStatsResponses,
  GetMutualFriendsData, GetMutualFriendsResponses,
  GetLikedCoursesData, GetLikedCoursesResponses,
  GetLikesLeaderboardData, GetLikesLeaderboardResponses,
  GetFollowingLeaderboardData, GetFollowingLeaderboardResponses,
  HasLikedCourseData, HasLikedCourseResponses,
  IsFollowingData, IsFollowingResponses,
  GetFollowingListData, GetFollowingListResponses,
  GetFollowersListData, GetFollowersListResponses,
  GetCourseLikesData, GetCourseLikesResponses,
  GetCourseLikeCountData, GetCourseLikeCountResponses
} from './socialTypes';
import { client as _heyApiClient } from '../../api/client.gen';
import type { Options } from '../common/apiTypes';

export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = ClientOptions<TData, ThrowOnError> & {
    client?: Client;
    meta?: Record<string, unknown>;
};

/**
 * 取消点赞课程
 * 取消对指定课程的点赞
 */
export const unlikeCourse = <ThrowOnError extends boolean = false>(options: Options<UnlikeCourseData, ThrowOnError>) => {
    return (options.client ?? _heyApiClient).post<UnlikeCourseResponses, unknown, ThrowOnError>({
        url: '/api/social/unlike',
        ...options,
        headers: {
            'Content-Type': 'application/json',
            ...options.headers
        }
    });
};

/**
 * 取消关注用户
 * 取消关注指定用户
 */
export const unfollowUser = <ThrowOnError extends boolean = false>(options: Options<UnfollowUserData, ThrowOnError>) => {
    return (options.client ?? _heyApiClient).post<UnfollowUserResponses, unknown, ThrowOnError>({
        url: '/api/social/unfollow',
        ...options,
        headers: {
            'Content-Type': 'application/json',
            ...options.headers
        }
    });
};

/**
 * 点赞课程
 * 给指定课程点赞
 */
export const likeCourse = <ThrowOnError extends boolean = false>(options: Options<LikeCourseData, ThrowOnError>) => {
    return (options.client ?? _heyApiClient).post<LikeCourseResponses, unknown, ThrowOnError>({
        url: '/api/social/like',
        ...options,
        headers: {
            'Content-Type': 'application/json',
            ...options.headers
        }
    });
};

/**
 * 关注用户
 * 关注指定用户
 */
export const followUser = <ThrowOnError extends boolean = false>(options: Options<FollowUserData, ThrowOnError>) => {
    return (options.client ?? _heyApiClient).post<FollowUserResponses, unknown, ThrowOnError>({
        url: '/api/social/follow',
        ...options,
        headers: {
            'Content-Type': 'application/json',
            ...options.headers
        }
    });
};

/**
 * 同步Redis数据
 * 手动将Redis中的社交数据同步到数据库（管理员功能）
 */
export const syncRedisToDatabase = <ThrowOnError extends boolean = false>(options?: Options<SyncRedisToDatabaseData, ThrowOnError>) => {
    return (options?.client ?? _heyApiClient).post<SyncRedisToDatabaseResponses, unknown, ThrowOnError>({
        url: '/api/social/admin/sync-redis',
        ...options
    });
};

/**
 * 获取用户关注列表
 * 获取指定用户的关注列表
 */
export const getUserFollowingList = <ThrowOnError extends boolean = false>(options: Options<GetUserFollowingListData, ThrowOnError>) => {
    return (options.client ?? _heyApiClient).get<GetUserFollowingListResponses, unknown, ThrowOnError>({
        url: '/api/social/user/{userId}/following',
        ...options
    });
};

/**
 * 获取用户粉丝列表
 * 获取指定用户的粉丝列表
 */
export const getUserFollowersList = <ThrowOnError extends boolean = false>(options: Options<GetUserFollowersListData, ThrowOnError>) => {
    return (options.client ?? _heyApiClient).get<GetUserFollowersListResponses, unknown, ThrowOnError>({
        url: '/api/social/user/{userId}/followers',
        ...options
    });
};

/**
 * 获取用户社交统计
 * 获取当前登录用户的社交统计信息
 */
export const getUserStats = <ThrowOnError extends boolean = false>(options?: Options<GetUserStatsData, ThrowOnError>) => {
    return (options?.client ?? _heyApiClient).get<GetUserStatsResponses, unknown, ThrowOnError>({
        url: '/api/social/user-stats',
        ...options
    });
};

/**
 * 获取共同好友
 * 获取当前用户与指定用户的共同好友列表
 */
export const getMutualFriends = <ThrowOnError extends boolean = false>(options: Options<GetMutualFriendsData, ThrowOnError>) => {
    return (options.client ?? _heyApiClient).get<GetMutualFriendsResponses, unknown, ThrowOnError>({
        url: '/api/social/mutual-friends/{userId}',
        ...options
    });
};

/**
 * 获取点赞课程列表
 * 获取当前登录用户点赞的课程列表
 */
export const getLikedCourses = <ThrowOnError extends boolean = false>(options?: Options<GetLikedCoursesData, ThrowOnError>) => {
    return (options?.client ?? _heyApiClient).get<GetLikedCoursesResponses, unknown, ThrowOnError>({
        url: '/api/social/liked-courses',
        ...options
    });
};

/**
 * 获赞排行榜
 * 获取课程获赞数量排行榜
 */
export const getLikesLeaderboard = <ThrowOnError extends boolean = false>(options?: Options<GetLikesLeaderboardData, ThrowOnError>) => {
    return (options?.client ?? _heyApiClient).get<GetLikesLeaderboardResponses, unknown, ThrowOnError>({
        url: '/api/social/leaderboard/likes',
        ...options
    });
};

/**
 * 关注排行榜
 * 获取关注数量排行榜
 */
export const getFollowingLeaderboard = <ThrowOnError extends boolean = false>(options?: Options<GetFollowingLeaderboardData, ThrowOnError>) => {
    return (options?.client ?? _heyApiClient).get<GetFollowingLeaderboardResponses, unknown, ThrowOnError>({
        url: '/api/social/leaderboard/following',
        ...options
    });
};

/**
 * 检查是否已点赞
 * 检查当前用户是否已点赞指定课程
 */
export const hasLikedCourse = <ThrowOnError extends boolean = false>(options: Options<HasLikedCourseData, ThrowOnError>) => {
    return (options.client ?? _heyApiClient).get<HasLikedCourseResponses, unknown, ThrowOnError>({
        url: '/api/social/is-liked/{courseId}',
        ...options
    });
};

/**
 * 检查是否已关注
 * 检查当前用户是否已关注指定用户
 */
export const isFollowing = <ThrowOnError extends boolean = false>(options: Options<IsFollowingData, ThrowOnError>) => {
    return (options.client ?? _heyApiClient).get<IsFollowingResponses, unknown, ThrowOnError>({
        url: '/api/social/is-following/{userId}',
        ...options
    });
};

/**
 * 获取关注列表
 * 获取当前登录用户的关注列表
 */
export const getFollowingList = <ThrowOnError extends boolean = false>(options?: Options<GetFollowingListData, ThrowOnError>) => {
    return (options?.client ?? _heyApiClient).get<GetFollowingListResponses, unknown, ThrowOnError>({
        url: '/api/social/following',
        ...options
    });
};

/**
 * 获取粉丝列表
 * 获取当前登录用户的粉丝列表
 */
export const getFollowersList = <ThrowOnError extends boolean = false>(options?: Options<GetFollowersListData, ThrowOnError>) => {
    return (options?.client ?? _heyApiClient).get<GetFollowersListResponses, unknown, ThrowOnError>({
        url: '/api/social/followers',
        ...options
    });
};

/**
 * 获取课程点赞用户
 * 获取点赞指定课程的用户列表
 */
export const getCourseLikes = <ThrowOnError extends boolean = false>(options: Options<GetCourseLikesData, ThrowOnError>) => {
    return (options.client ?? _heyApiClient).get<GetCourseLikesResponses, unknown, ThrowOnError>({
        url: '/api/social/course-likes/{courseId}',
        ...options
    });
};

/**
 * 获取课程点赞数
 * 获取指定课程的点赞数量
 */
export const getCourseLikeCount = <ThrowOnError extends boolean = false>(options: Options<GetCourseLikeCountData, ThrowOnError>) => {
    return (options.client ?? _heyApiClient).get<GetCourseLikeCountResponses, unknown, ThrowOnError>({
        url: '/api/social/course-like-count/{courseId}',
        ...options
    });
};